// pages/daohang/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navdata: {
      img: 4,
      text: 4
    },
    nowx: 0,
    nowy: 0,
    getResource: [],
    markers: [{
      iconPath: '/icons/address.png',
      id: 1,
      latitude: 26.898331,
      longitude: 112.555423,
      width: 30,
      height: 45
    }, {
      iconPath: '/icons/address.png',
      id: 2,
      latitude: 26.902414,
      longitude: 112.614975,
      width: 30,
      height: 45
    }]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

    // 请求数据
    var that = this;
    wx.request({
      url: 'https://jiaoyu.mogochina.com/public/index.php/api/get_maps?position=衡阳',
      success: function(res) {
        that.setData({
          getResource: res.data.data
        })
      }
    })

    // 获取位置
    wx.getLocation({
      type: 'wgs84',
      success: function(res) {
        var x = res.latitude
        var y = res.longitude
        that.setData({
          nowx: x,
          nowy: y
        })
      }
    })

    // 获取map
    this.mapCtx = wx.createMapContext('myMap');
    this.mapCtx.includePoints({
      padding: [100],
      points: [{
        latitude: 26.898331,
        longitude: 112.555423,
      }, {
        latitude: 26.902414,
        longitude: 112.614975,
      }]
    })
  },
  mapnav(e) {
    var a = e.target.dataset.mapdata;
    var xy = a.split(',')
    var x = xy[0] * 1;
    var y = xy[1] * 1;
    wx.openLocation({
      latitude: y,
      longitude: x
    })
  }
}) + 8